import 'package:enterprise_v8/app/components/common/no_permissions_widget.dart';
import 'package:enterprise_v8/app/components/custom_app_bar.dart';
import 'package:enterprise_v8/app/components/drawer_title.dart';
import 'package:enterprise_v8/app/core/core.dart';
import 'package:enterprise_v8/app/core/ext/widget_extension.dart';
import 'package:enterprise_v8/app/core/utils/user_manager.dart';

import 'workbench_control.dart';

/// 工作台 (原型测试页面,不做正式用)
class WorkbenchPage extends StatelessWidget {
  const WorkbenchPage({super.key});

  @override
  Widget build(BuildContext context) {
    final control = Get.put(WorkbenchControl());
    return GetBuilder(
        init: control,
        builder: (_) {
          // 没有登录时不执行操作
          if (!UserManager.isLoggedIn || control.titleList.isEmpty) {
            return const NoPermissionsWidget();
          }
          return Scaffold(
            appBar: CustomAppBar(
              titleText: control.titleList[control.selectIndex].expandTitle,
              automaticallyImplyLeading: false,
            ),
            body: Scaffold(
              body: Row(
                children: [
                  Container(
                    width: AppDimens.dp60,
                    color: Colors.white,
                    alignment: Alignment.topCenter,
                    child: Column(
                      children: [
                        Expanded(
                          child: SingleChildScrollView(
                              child: Column(
                                children: control.titleList.map((e) {
                                  return DrawerTitle.title(e.title, e.icon, isSelected: control.selectIndex == control.titleList.indexOf(e)).click(() {
                                    control.selectLeftMenu(control.titleList.indexOf(e));
                                  });
                                }).toList()..add(AppGaps.vGap10),
                              )),
                        ),
                      ],
                    ),
                  ),
                  Expanded(
                    child: Container(
                      color: const Color(0xffF5F5F6),
                      child: control.titleList[control.selectIndex].pages[control.titleList[control.selectIndex].currentPageTitle],
                    ),
                  ),
                ],
              ),
            ),
          );
        });
  }

}
